<?php
namespace app\oem\controller;
use think\Controller;
use think\Db;
use think\request;
use app\common\controller\OemBaseController;

class Helps extends OemBaseController
{
	//帮助列表
    public function helps()
    {
    	if(input("pid")){
    		$pid=input('pid');
    	}else{
    		$pid='1,2,3,4,5,6';
    	}
    	$list = Db::name('sys_helps')->where('pid in ('.$pid.')')->order('add_time desc')->paginate(8);
        $this->assign('list',$list);
        $this->assign('empty','<span class="empty">没有数据</span>');
    	return $this->fetch();
    }
    //帮助详情
    public function helps_show()
    {
    	$id=input('id');
    	$data = Db::name('sys_helps')->where('id',$id)->find();
    	$this->assign('data',$data);
    	return $this->fetch();
    }
    
    
    //更新日志
    public function iteration()
    {
    	$list = Db::name('sys_iteration')->order('add_time desc')->select();
        $this->assign('list',$list);
        $this->assign('empty','<span class="empty">没有数据</span>');
    	return $this->fetch();
    }
    
    
    //平台公告OEM发布
    public function notice()
    {
    	if(session('user_level')==1){
    		$id = session('d_id');
    	}else{
    		$id = session('oem_id');
    	}
    	$list = Db::name('sys_notice')->where('oem_id',$id)->order('add_time desc')->paginate(8);
        $this->assign('list',$list);
        $this->assign('empty','<span class="empty">没有数据</span>');
    	return $this->fetch();
    }
    //平台公告详情
    public function notice_show()
    {
    	$id=input('id');
    	$data = Db::name('sys_notice')->where('id',$id)->find();
    	$this->assign('data',$data);
    	return $this->fetch();
    }
    //平台公告增加强
    public function notice_add()
    {
    	if($_POST){
            $data['title']		=$_POST['title'];
            $data['content']	=$_POST['content'];
            $data['oem_id']		=session('d_id');
            $data['add_time'] 	=now_time();
            $result=Db::name('sys_notice')->insert($data);//分组数据库
            if($result){
			  return json(['code'=>200,'msg'=>'成功']);
		    }else{
		      return json(['code'=>402,'msg'=>'失败']);
		    }
            
        }
    	return $this->fetch();
    }
    //平台公告删除
    public function notice_del()
    {
    	$result =Db::name('sys_notice')->where('id', input("id"))->delete();;
        if($result){
		 return json(['code'=>200,'msg'=>'成功']);
	    }else{
	      return json(['code'=>402,'msg'=>'失败']);
	    } 
    }
    
    public function config(){
	   	$list=Db::name('tg_admin_system')->select();	
	    	for($i=0;$i<count($list);$i++){
	    		$value=unserialize($list[$i]['value']);
	    		$name[$i]=$list[$i]['name'];
	    		$this->assign('config'.$i,$value);
	    	}
	    return $this->fetch('config',['name'=>$name]);
   }
   
   public function save()
    {
    	$param=input('post.');
		if(in_array('fx_config',$param)){
    		$where['name']=$param['fx_config'];
    	}
    	$value['value']=serialize($param);
    	$list=Db::name('tg_admin_system')->where($where)->update($value);
        if($list){
		 	return json(['code'=>200,'msg'=>'操作成功']);
	    }else{
	      	return json(['code'=>402,'msg'=>'操作失败']);
	    } 
    }
    
    
}
